package org.jeecg.modules.api.wlhy.customer;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerAddressReceive;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerAddressSend;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerReq;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerAddressReceiveService;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerAddressSendService;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerService;
import org.jeecg.modules.wlhy.hycustomerbank.entity.HyCustomerBank;
import org.jeecg.modules.wlhy.hycustomerbank.service.IHyCustomerBankService;
import org.jeecg.modules.wlhy.losssetting.entity.HyLossGoodsUnitPrice;
import org.jeecg.modules.wlhy.losssetting.entity.HyLossProportion;
import org.jeecg.modules.wlhy.losssetting.service.IHyLossGoodsUnitPriceService;
import org.jeecg.modules.wlhy.losssetting.service.IHyLossProportionService;
import org.jeecg.modules.wlhy.order.entity.HyOrder;
import org.jeecg.modules.wlhy.order.service.IHyOrderService;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNoteDTO;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Api(tags = "app货主")
@RestController
@RequestMapping("/api/wlhy/customer")
@Slf4j
public class ApiCustomerController extends JeecgController<HyCustomer, IHyCustomerService> {
    @Autowired
    private IHyCustomerService hyCustomerService;

    @Autowired
    private IHyCustomerAddressReceiveService hyCustomerAddressReceiveService;

    @Autowired
    private IHyCustomerAddressSendService hyCustomerAddressSendService;

    @Autowired
    private IHyLossGoodsUnitPriceService lossGoodsUnitPriceService;

    @Autowired
    private IHyLossProportionService lossProportionService;

    @Resource
    private BaseCommonService baseCommonService;

    @Autowired
    private IHyCustomerBankService hyCustomerBankService;

    @Autowired
    private IHyShippingNoteService hyShippingNoteService;

    @Autowired
    private IHyOrderService hyOrderService;

    private static final Logger LOGGER = LoggerFactory.getLogger(ApiCustomerController.class);

    private String drDateSql="TO_DAYS(status_dt_sign) = TO_DAYS(NOW())";//当日sql
    private String ztDateSql="TO_DAYS( NOW( ) ) - TO_DAYS( status_dt_sign) = 1";//昨日sql
    private String dzDateSql="YEARWEEK(date_format(status_dt_sign,'%Y-%m-%d')) = YEARWEEK(now())";//当周sql
    private String dyDateSql="DATE_FORMAT( status_dt_sign, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )";//当月sql


    /**
     * 添加
     *
     * @param hyCustomer
     * @return
     */
    // @AutoLog(value = "app货主-添加货主信息")
    @ApiOperation(value = "app货主-添加货主信息", notes = "app货主-添加货主信息")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody @Valid HyCustomerReq hyCustomer) {
        LoginUser sysUser = UserUtil.getLoginUser();
        if (StringUtils.isEmpty(hyCustomer.getIdcardExpiredDate())) {
            throw new JeecgBootException("身份证过期时间不允许为空");
        }
        Date idcardExpiredDate = DateUtils.getStrToDate(hyCustomer.getIdcardExpiredDate());
        if (idcardExpiredDate == null) {
            throw new JeecgBootException("身份证过期时间格式不正确,请重新填写!");
        }
        if (idcardExpiredDate.before(new Date())) {
            throw new JeecgBootException("身份证过期时间需要一个将来时间,请重新填写!");
        }
//        if(StringUtils.isEmpty(hyCustomer.getCustomerShoreName())){
//            return Result.error("简称不能为空");
//        }
//        if(hyCustomer.getCustomerShoreName().length() > 5){
//            return Result.error("简称长度不能超过5个字");
//        }
        HyCustomer hyCustomerDb = hyCustomerService.getCustomerByUserId(sysUser.getId());
        if (hyCustomerDb != null) {
            return Result.error("您的货主信息已存在,不能重复补充！");
        }
        hyCustomer.setUserId(sysUser.getId());
        hyCustomer.setCustomerChannel("2");

        if ("1".equals(hyCustomer.getCustomerType())) {
            hyCustomer.setCustomerName(hyCustomer.getContactName());
        }
        hyCustomerService.saveCustomer(HyCustomerReqTOHyCustomer(hyCustomer));
        baseCommonService.addLog("app货主: " + sysUser.getRealname() + ",添加货主信息成功！",
                CommonConstant.LOG_TYPE_2, CommonConstant.OPERATE_TYPE_2, null);
        return Result.OK("添加成功!");

    }


    /**
     * 编辑
     *
     * @param hyCustomer
     * @return
     */
    @AutoLog(value = "hy_customer-编辑")
    @ApiOperation(value = "hy_customer-编辑", notes = "hy_customer-编辑")
    @PutMapping(value = "/edit")
    public Result<?> edit(@RequestBody HyCustomer hyCustomer) {
        if ("1".equals(hyCustomer.getCustomerType())) {
            hyCustomer.setCustomerName(hyCustomer.getContactName());
        }
//        if(StringUtils.isEmpty(hyCustomer.getCustomerShoreName())){
//            return Result.error("简称不能为空");
//        }
//        if(hyCustomer.getCustomerShoreName().length() > 5){
//            return Result.error("简称长度不能超过5个字");
//        }
        hyCustomerService.updateById(hyCustomer);
        return Result.OK("修改成功!");
    }


//    @AutoLog(value = "hy_customer-获取当前登陆货主信息")
    @ApiOperation(value = "hy_customer-获取当前登陆货主信息", notes = "hy_customer-获取当前登陆货主信息")
    @GetMapping(value = "/getCustomer")
    public Result<?> getCustomer(HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
        return Result.OK(hyCustomer);
    }

//    @AutoLog(value = "获取货主常用字典项")
    @ApiOperation(value = "获取货主常用字典项", notes = "获取货主常用字典项")
    @GetMapping(value = "/getCustomerDict")
    public Result<?> getCustomerDict(HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);

        List<HyCustomerAddressReceive> addressReceiveList = hyCustomerAddressReceiveService.list(new QueryWrapper<HyCustomerAddressReceive>()
                .eq("customer_id", hyCustomer.getId())
                .eq("iz_used", "1"));

        List<HyCustomerAddressSend> addressSendList = hyCustomerAddressSendService.list(new QueryWrapper<HyCustomerAddressSend>()
                .eq("customer_id", hyCustomer.getId())
                .eq("iz_used", "1"));

        List<HyLossGoodsUnitPrice> lossGoodsUnitPriceList = lossGoodsUnitPriceService.list(new QueryWrapper<HyLossGoodsUnitPrice>()
                .eq("customer_id", hyCustomer.getId()));

        List<HyLossProportion> lossProportionList = lossProportionService.list(new QueryWrapper<HyLossProportion>()
                .eq("customer_id", hyCustomer.getId()));

        Map<String, Object> datas = new HashMap<>();
        datas.put("addressReceiveList", addressReceiveList);//收货地址
        datas.put("addressSendList", addressSendList);//发货地址
        datas.put("lossGoodsUnitPriceList", lossGoodsUnitPriceList);//亏损单价
        datas.put("lossProportionList", lossProportionList);//亏损比例

        return Result.OK(datas);
    }


    @ApiOperation(value = "app货主-银行卡保存", notes = "app货主银行卡保存")
    @PostMapping(value = "/bankcard/save")
    public Result<?> hyCustomerBankSave(@RequestBody @Valid HyCustomerBank hyCustomerBank,
                                        BindingResult bindingResult,
                                        HttpServletRequest req) {
        Result<JSONObject> result;


        if (bindingResult.hasErrors()) {
            throw new JeecgBootException(bindingResult.getFieldError().getDefaultMessage());
        } else {
            if (hyCustomerBank.getBankPhone() != null && hyCustomerBank.getBankPhone().length() != 11) {
                throw new JeecgBootException("手机号应为11位数。");
            }
            if (hyCustomerBank.getBankPhone() != null && !hyCustomerBank.getBankPhone().matches(CommonConstant.REGEX_MOBILE)) {
                throw new JeecgBootException("手机号格式错误！");
            }
            hyCustomerBank.setBankNum(hyCustomerBank.getBankNum().replaceAll(" ",""));
            HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
            hyCustomerBank.setUserId(hyCustomer.getUserId());
            hyCustomerBank.setCustomerId(hyCustomer.getId());
            hyCustomerBank.setCreateBy(hyCustomerBank.getBankName());
            hyCustomerBank.setUpdateBy(hyCustomerBank.getBankName());
            result = hyCustomerBankService.saveCustomerBank(hyCustomerBank);
            if (!result.isSuccess()) {
               return result;
            }
            //添加日志
            baseCommonService.addLog("货主用户: " + hyCustomerBank.getBankName() + ",货主银行信息保存成功！",
                    CommonConstant.LOG_TYPE_2, CommonConstant.OPERATE_TYPE_2, null);
            return result;
        }
    }

    @ApiOperation(value = "app货主-银行卡列表", notes = "app货主-银行卡列表")
    @GetMapping(value = "/bank/list")
    public Result<?> queryPageList(HyCustomerBank hyCustomerBank,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
        QueryWrapper<HyCustomerBank> queryWrapper = QueryGenerator.initQueryWrapper(hyCustomerBank, req.getParameterMap());
        queryWrapper.eq("user_id", hyCustomer.getId());
        queryWrapper.eq("iz_used", "1");
        Page<HyCustomerBank> page = new Page<>(pageNo, pageSize);
        IPage<HyCustomerBank> pageList = hyCustomerBankService.page(page, queryWrapper);

        return Result.OK(pageList);
    }

    @AutoLog(value = "app货主-银行卡解绑")
    @ApiOperation(value = "app货主-银行卡解绑", notes = "app货主-银行卡解绑")
    @PostMapping(value = "/bank/unbundling")
    public Result<?> unBundLing(@RequestParam(name = "id") String id,
                                HttpServletRequest req) {
        Result<JSONObject> result;
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
        result = hyCustomerBankService.unBundLing(id);
        //添加日志
        baseCommonService.addLog("货主用户: " + hyCustomer.getCustomerName() + ",货主银行卡解绑成功！",
                CommonConstant.LOG_TYPE_2, CommonConstant.OPERATE_TYPE_3, null);
        return result;
    }

    public static HyCustomer HyCustomerReqTOHyCustomer(HyCustomerReq hyCustomerReq) {
        if (hyCustomerReq == null) {
            return null;
        }
        HyCustomer hyCustomer = new HyCustomer();
        hyCustomer.setId(hyCustomerReq.getId());
        hyCustomer.setCustomerType(hyCustomerReq.getCustomerType());
        hyCustomer.setCustomerChannel(hyCustomerReq.getCustomerChannel());
        hyCustomer.setCustomerName(hyCustomerReq.getCustomerName());
        hyCustomer.setLegalName(hyCustomerReq.getLegalName());
        hyCustomer.setCustomerShoreName(hyCustomerReq.getCustomerShoreName());
        hyCustomer.setLegalPhone(hyCustomerReq.getLegalPhone());
        hyCustomer.setCreditCode(hyCustomerReq.getCreditCode());
        hyCustomer.setBusinessLicenseExpiredDate(
                StringUtils.isNotEmpty(hyCustomerReq.getBusinessLicenseExpiredDate()) ? DateUtils.getStrToDate(hyCustomerReq.getBusinessLicenseExpiredDate()) : null
        );
        hyCustomer.setBusinessLicenseImg(hyCustomerReq.getBusinessLicenseImg());
        hyCustomer.setBusinessLicenseImg2(hyCustomerReq.getBusinessLicenseImg2());

        hyCustomer.setLegalIdcardImg(hyCustomerReq.getLegalIdcardImg());
        hyCustomer.setTosUploadStatus(hyCustomerReq.getLegalIdcardBackImg());

        hyCustomer.setProvinceCode(hyCustomerReq.getProvinceCode());
        hyCustomer.setCityCode(hyCustomerReq.getCityCode());
        hyCustomer.setCountyCode(hyCustomerReq.getCountyCode());
        hyCustomer.setDetailAddress(hyCustomerReq.getDetailAddress());
        hyCustomer.setContactName(hyCustomerReq.getContactName());
        hyCustomer.setLoginPhone(hyCustomerReq.getLoginPhone());
        hyCustomer.setIdcard(hyCustomerReq.getIdcard());
        hyCustomer.setIdcardImg(hyCustomerReq.getIdcardImg());
        hyCustomer.setIdcardBackImg(hyCustomerReq.getIdcardBackImg());
        hyCustomer.setIdcardExpiredDate(
                StringUtils.isNotEmpty(hyCustomerReq.getIdcardExpiredDate()) ? DateUtils.getStrToDate(hyCustomerReq.getIdcardExpiredDate()) : null
        );
//        hyCustomer.setCooperAgreement(hyCustomerReq.getCooperAgreement());
        hyCustomer.setCompetentTaxAuthority(hyCustomerReq.getCompetentTaxAuthority());
        hyCustomer.setIzUsed(hyCustomerReq.getIzUsed());
        hyCustomer.setExamineStatus(hyCustomerReq.getExamineStatus());
        hyCustomer.setExamineDate(hyCustomerReq.getExamineDate());
        hyCustomer.setExamineRemark(hyCustomerReq.getExamineRemark());
        hyCustomer.setUserId(hyCustomerReq.getUserId());
        hyCustomer.setOrgId(hyCustomerReq.getOrgId());
        hyCustomer.setSysOrgCode(hyCustomerReq.getSysOrgCode());
        hyCustomer.setCreateBy(hyCustomerReq.getCreateBy());
        hyCustomer.setCreateTime(hyCustomerReq.getCreateTime());
        hyCustomer.setUpdateBy(hyCustomerReq.getUpdateBy());
        hyCustomer.setUpdateTime(hyCustomerReq.getUpdateTime());
        hyCustomer.setDelFlag(hyCustomerReq.getDelFlag());

        hyCustomer.setZczb(hyCustomerReq.getZczb());
        hyCustomer.setJyfw(hyCustomerReq.getJyfw());
        hyCustomer.setClrq(
                StringUtils.isNotEmpty(hyCustomerReq.getClrq()) ? DateUtils.getStrToDate(hyCustomerReq.getClrq()) : null

        );
        return hyCustomer;
    }


    @ApiOperation(value = "app货主-统计列表", notes = "app货主-统计列表")
    @GetMapping(value = "/Statistics/list")
    public Result<?> StatisticsList(HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);

            //在途运单数
        int intransitCount = hyShippingNoteService.count(new QueryWrapper<HyShippingNote>().eq("shipping_status", "3")
                .eq("customer_id", hyCustomer.getId())
        );
        QueryWrapper<HyShippingNote> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("shipping_status","4");
        queryWrapper.eq("customer_id", hyCustomer.getId());
        int ztCount = hyShippingNoteService.getZtCount(queryWrapper);
        //待签收运单数
        int NoSignedCount = hyShippingNoteService.count(new QueryWrapper<HyShippingNote>().eq("shipping_status", "4")
                .eq("customer_id", hyCustomer.getId()));
        QueryWrapper<HyShippingNote> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("shipping_status","4");
        queryWrapper1.eq("customer_id", hyCustomer.getId());
        int qsCount = hyShippingNoteService.getCount(queryWrapper);


        //查询当日已签收运单
        HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayList(hyCustomer.getId(), "5");
        Map CountList = new HashMap();
        CountList.put("ztCount", ztCount);
        CountList.put("intransitCount", intransitCount);
        CountList.put("NoSignedCount", NoSignedCount);
        CountList.put("qsCount", qsCount);
        CountList.put("YesSignedCount", sameDay);
        return Result.OK(CountList);
    }


    @ApiOperation(value = "app货主-统计列表", notes = "app货主-统计列表")
    @GetMapping(value = "/Statistics/listZtAndDqs")
    public Result<?> listZtAndDqs(   @RequestParam(name = "zt") String zt, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);

        QueryWrapper<HyShippingNoteTongJiDTO> queryWrapper = new QueryWrapper();

        Page<HyShippingNoteTongJiDTO> page = new Page<>(pageNo, pageSize);

        if(StringUtils.isNotEmpty(zt)){
            //在途
            if("0".equals(zt)){
                //在途运单详情
                IPage<HyShippingNoteTongJiDTO> intransitList = hyShippingNoteService.intransitList(page,queryWrapper,hyCustomer.getId(), "3");
                return Result.OK(intransitList);
            }else{
                //待签收运单详情
                IPage<HyShippingNoteTongJiDTO> NoSignedList = hyShippingNoteService.intransitList(page,queryWrapper,hyCustomer.getId(), "4");
                return Result.OK(NoSignedList);
            }
        }else{
            return Result.error("暂无数据");
        }


    }



    @ApiOperation(value = "app货主-统计列表", notes = "app货主-统计列表")
    @GetMapping(value = "/Statistics/listQs")
    public Result<?> StatisticsListQs(@RequestParam(name = "zt") String zt, HttpServletRequest req,
                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(name = "rqData") String rqData
    ) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
        QueryWrapper<HyShippingNoteTongJiDTO> queryWrapper = new QueryWrapper();

        Page<HyShippingNoteTongJiDTO> page = new Page<>(pageNo, pageSize);



        if(StringUtils.isNotEmpty(zt)){
            if ("0".equals(zt)) {

                //查询当日已签收运单
                HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayListSql(hyCustomer.getId(), "5", drDateSql,"","");
                //查询当日已签收运单详情
                IPage<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2SqlW(page, queryWrapper, hyCustomer.getId(), drDateSql,"","");

                Map CountList = new HashMap();
                CountList.put("YesSignedCount", sameDay);
                CountList.put("sameDayList", sameDayList);
                return Result.OK(CountList);
            } else if ("1".equals(zt)) {
                //查询昨天已签收运单
                HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayListSql(hyCustomer.getId(), "5", ztDateSql,"","");
                //查询昨天已签收运单详情
                IPage<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2SqlW(page, queryWrapper, hyCustomer.getId(), ztDateSql,"","");

                Map CountList = new HashMap();
                CountList.put("YesSignedCount", sameDay);
                CountList.put("sameDayList", sameDayList);
                return Result.OK(CountList);
            } else if ("2".equals(zt)) {
                //查询这周已签收运单
                HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayListSql(hyCustomer.getId(), "5", dzDateSql,"","");

                //查询这周已签收运单详情
                IPage<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2SqlW(page, queryWrapper, hyCustomer.getId(), dzDateSql,"","");

                Map CountList = new HashMap();


                CountList.put("YesSignedCount", sameDay);
                CountList.put("sameDayList", sameDayList);
                return Result.OK(CountList);
            } else {
                //查询本月已签收运单
                HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayListSql(hyCustomer.getId(), "5", dyDateSql,"","");

                //查询本月已签收运单详情
//            List<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2Sql(hyCustomer.getId(), "5", "DATE_FORMAT( status_dt_sign, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )");
                IPage<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2SqlW(page, queryWrapper, hyCustomer.getId(), dyDateSql,"","");

                Map CountList = new HashMap();


                CountList.put("YesSignedCount", sameDay);
                CountList.put("sameDayList", sameDayList);
                return Result.OK(CountList);
            }
        }else{
            if(StringUtils.isNotEmpty(rqData)){
                String[] datas = rqData.split("至");
                String starData=datas[0];
                String endData=datas[1];

                if(StringUtils.isNotEmpty(starData) && StringUtils.isNotEmpty(endData)){
                    //时间段
                    //查询运单数
                    HyShippingNoteTongJiDTO sameDay = hyShippingNoteService.sameDayListSql(hyCustomer.getId(), "5","",starData,endData);
                    //查询运单详情
                    IPage<HyShippingNoteTongJiDTO> sameDayList = hyShippingNoteService.sameDayList2SqlW(page, queryWrapper, hyCustomer.getId(),"",starData,endData);
                    Map CountList = new HashMap();

                    CountList.put("YesSignedCount", sameDay);
                    CountList.put("sameDayList", sameDayList);
                    return Result.OK(CountList);
                }else{
                    return Result.OK();
                }




            }else{
                return Result.OK();
            }
        }



    }

    @ApiOperation(value = "app货主-统计列表", notes = "app货主-统计列表")
    @GetMapping(value = "/Statistics/listById")
    public Result<?> StatisticsListById(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "rqzt") String rqzt, @RequestParam(name = "rqData") String rqData, @RequestParam(name = "orderId") String orderId, HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);
        QueryWrapper<HyShippingNoteTongJiDTO> queryWrapper = new QueryWrapper();

        Page<HyShippingNoteTongJiDTO> page = new Page<>(pageNo, pageSize);
       /* if ("1".equals(zt)) {
            //在途运单数
            IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"3", hyCustomer.getId(), orderId);
            return Result.OK(list);
        }
        if ("2".equals(zt)) {
            //待签收运单数
            IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"4", hyCustomer.getId(), orderId);
            return Result.OK(list);
        } else {



        }*/
        if(StringUtils.isNotEmpty(rqzt)){
            if("0".equals(rqzt)){
                //当日已签收运单数
                IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"5", hyCustomer.getId(), orderId,drDateSql);
                return Result.OK(list);
            }else if("1".equals(rqzt)){
                //昨天已签收运单数
                IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"5", hyCustomer.getId(), orderId,ztDateSql);
                return Result.OK(list);
            }else if("2".equals(rqzt)){
                //当周已签收运单数
                IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"5", hyCustomer.getId(), orderId,dzDateSql);
                return Result.OK(list);
            }else {
                //当月已签收运单数
                IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiList(page, queryWrapper,"5", hyCustomer.getId(), orderId,dyDateSql);
                return Result.OK(list);
            }
        }else{
            if(StringUtils.isNotEmpty(rqData)){
                String[] datas = rqData.split("至");
                String starData=datas[0];
                String endData=datas[1];

                /*if(StringUtils.isNotEmpty(starData)){
                    queryWrapper.ge("hy_shipping_note.status_dt_sign",starData);
                }
                if(StringUtils.isNotEmpty(endData)){
                    queryWrapper.le("hy_shipping_note.status_dt_sign",endData);
                }*/

                //时间段
                IPage<HyShippingNoteDTO> list = hyShippingNoteService.tongjiRqList(page, queryWrapper,"5", hyCustomer.getId(), orderId,starData,endData);
                return Result.OK(list);
            }else{
                return Result.OK();
            }

        }


    }


    @ApiOperation(value = "app货主-待开票货源列表", notes = "app货主-待开票货源列表")
    @GetMapping(value = "/Statistics/daiKaiHuoYuanList")
    public Result<?> daiKaiHuoYuanList(HttpServletRequest req) {
        HyCustomer hyCustomer = hyCustomerService.getCustomer(req);

        List<HyOrder> list = hyOrderService.list(new QueryWrapper<HyOrder>().eq("customer_id", hyCustomer.getId())
                .eq("del_flag", 0)
        );

        return Result.OK(list);


    }


}
